<template>
  <div>
    <Back :title=" $t('VolumeContent_dataVolumeDetail')"></Back>
    <div v-if="volume">
      <div class="from">
        <div class="title">
         {{  $t('VolumeContent_dataVolumeDetailInfo')}}
        </div>
        <ul>
          <li>
            <div class="head">ID</div>
            <div class="body" :title="volume.Name">
              {{ volume.Name }}
            </div>
          </li>
          <li>
            <div class="head">   {{  $t('VolumeContent_createTime')}} </div>
            <div class="body">
              {{ volume.CreatedAt }}
            </div>
          </li>
          <li>
            <div class="head">   {{  $t('VolumeContent_installPath')}}</div>
            <div class="body" :title="volume.Mountpoint">
              {{ volume.Mountpoint }}
            </div>
          </li>
          <li>
            <div class="head">   {{  $t('VolumeContent_driver')}}</div>
            <div class="body">
              {{ volume.Driver }}
            </div>
          </li>
        </ul>
        <el-button type="danger" icon="el-icon-delete" @click="volumeDel" style="margin: 20px 0px 0px 10px">删除卷</el-button>
      </div>
    </div>
    <div v-else>
        {{  $t('VolumeContent_networkError')}}
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Button } from 'element-ui'
import Back from '@/components/Back'
import post from '@/utils/post'
Vue.use(Button)

export default {
  data () {
    return {
      volume: null
    }
  },
  mounted () {
    const docker = `curl --unix-socket /var/run/docker.sock -s "http:/v1.40/volumes/${this.$route.params.id}"` // 查询卷列表
    post({ docker }, res => {
      if (!res.message) {
        this.volume = res
      }
    }, this)
  },
  methods: {
    // 删除卷
    volumeDel () {
      if (!confirm(this.$t('VolumeContent_confirmDeleteDataVolume')+'？')) {
        return
      }
      const docker = `curl -w %{http_code} --unix-socket /var/run/docker.sock -s -X DELETE "http:/v1.40/volumes/${this.volume.Name}"` // 删除数据卷
      post({ docker }, res => {
        if (res >= 200 && res < 300) {
          this.$message({
            showClose: true,
            message: '数据卷删除成功！',
            type: 'success'
          })
          this.$router.go(-1)
        } else {
          this.$message({
            showClose: true,
            message: this.$t('VolumeContent_networkBadTryLater'),
            type: 'error'
          })
        }
      }, this)
    }
  },
  components: {
    Back
  }
}
</script>

<style lang="scss" scoped>
.from{
  margin-top: 30px;
}
ul{
  li{
    display: flex;
    font-size: 14px;
    color: #333;
    .head{
      min-height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      width: 125px;
      margin-right: 30px;
      font-size: 16px;
      color: #067FB5;
      border-radius: 5px;
      background: #fff;
      border: 1px solid #067FB5;
    }
    &:nth-child(2n-1){
      background: #fff;
      .head:nth-child(2n-1){
        background: #F7FCFF;
      }
    }
    .body{
      padding: 5px 0px;
      font-size: 13px;
      width: 100%;
      overflow: hidden; //超出部分隐藏
      text-overflow: ellipsis; //超出部分显示...
      white-space: nowrap; //文本强制一行显示
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  }
}
</style>
